package iterator;

/**
 * @author zhangxi
 * @date 2021/9/29
 */
public class ClassRoomInterator implements Interator {

    private ClassRoom classRoom;

    private int index;

    public ClassRoomInterator(ClassRoom classRoom) {
        this.classRoom = classRoom;
        this.index = 0;
    }

    public boolean hasNext() {
        if (index < classRoom.getLength()) {
            return true;
        } else {
            return false;
        }
    }

    public Object next() {
        Student student = classRoom.getStudent(index);
        index++;
        return student;
    }
}
